package cn.edu.bjut.homework.chapter7;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.awt.Color;
import java.awt.ComponentOrientation;

public class GridLayoutTester {
	private JFrame frm;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GridLayoutTester window = new GridLayoutTester();
					window.frm.setVisible(true);
					window.frm.pack();
					window.frm.setLocationRelativeTo(null);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public GridLayoutTester() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frm = new JFrame();
		frm.setBounds(100, 100, 450, 300);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JTextArea txtArea = new JTextArea();
		txtArea.setLineWrap(true);
		txtArea.setBackground(Color.PINK);
		frm.getContentPane().add(txtArea, BorderLayout.NORTH);
		txtArea.setColumns(10);
		txtArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

		JPanel panel = new JPanel();
		frm.getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(new GridLayout(4, 4, 3, 3));

		String[] names = { "7", "8", "9", "/", "4", "5", "6", "*", 
				"1", "2", "3", "-", "0", ".", "=", "+" };
		JButton[] buttons = new JButton[names.length];
		for (int i = 0; i < names.length; i++) {
			buttons[i] = new JButton(names[i]);
			panel.add(buttons[i]);
		}
	}
}